package easy;

import java.util.Arrays;

public class Solution_1608 {
    public int specialArray(int[] nums) {
        int[] array = new int[1001];
        for (int num : nums) {
            array[num]++;
        }
        for (int i = array.length - 1, count = 0; i >= 0; i--) {
            if (array[i]>0) {
                count += array[i];
            }
            if (count==i) {
                return i;
            }
        }
        return -1;
    }

    public static void main(String[] args) {
        Solution_1608 model = new Solution_1608();
    }
}
